import fs from 'node:fs'
import { execa, execaSync } from 'execa'

// 仅取文件夹
const dirs = fs.readdirSync('packages').filter((p) => {
  if (!fs.statSync(`packages/${p}`).isDirectory()) {
    return false
  }
  return true
})
 
async function build(target) {
  // -c 执行rollup的配置
  await execa('rollup', ['-c', '--environment', `TARGET:${target}`], {
    stdio: 'inherit'
  })
}

async function runParaller(dirs, itemfn) {
  let result = []
  for (let item of dirs) {
    result.push(itemfn(item))
  }
  return Promise.all(result)
}

runParaller(dirs, build).then(() => {
  console.log('打包成功')
})

console.log(dirs)
